import java.util.Scanner;

public class JAlberto {

	private static boolean iguales(int[][] s1, int[][] s2) {
		boolean sol = true;
		for (int i = 0; sol && i < 9; i++) {
			for (int j = 0; sol && j < 9; j++) {
				sol = sol
						&& (s1[i][j] == 0 && s2[i][j] == 0 || s1[i][j] != 0
								&& s2[i][j] != 0);
			}
		}
		return sol;
	}

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long nCasos = in.nextLong();
		in.nextLine();
		for (long n = 0; n < nCasos; n++) {
			in.nextLine();
			int[][] s = new int[9][9];
			int digitos = 0;
			for (int f = 0; f < 9; f++) {
				String fila = in.nextLine();
				for (int c = 0; c < 9; c++) {
					if (fila.charAt(c) != '-') {
						digitos++;
						s[f][c] = ((int) fila.charAt(c)) - 48;
					}
				}
			}
			if (digitos <= 32 && (iguales(s, rotar(s)))) {
				System.out.println("SI");
			} else {
				System.out.println("NO");
			}
		}
	}

	private static int[][] rotar(int[][] s) {
		int[][] sol = new int[9][9];
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				sol[8 - i][8 - j] = s[i][j];
			}
		}
		return sol;
	}
}
